<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WaveSurfer Symmetric</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/wavesurfer.js/7.4.12/wavesurfer.min.js"></script>
    <style>
        body {
            background-color: #1a1a1a;
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            min-height: 100vh;
            font-family: Arial, sans-serif;
        }

        .controls {
            margin: 20px;
        }

        .button {
            padding: 10px 20px;
            background: #4CAF50;
            border: none;
            border-radius: 5px;
            color: white;
            cursor: pointer;
            margin: 0 5px;
        }

        #waveform {
            width: 800px;
            background: #000;
            border-radius: 10px;
            padding: 20px;
        }
    </style>
</head>
<body>
    <div class="controls">
        <button class="button" onclick="loadAudio()">Load Audio</button>
        <button class="button" onclick="togglePlay()">Play/Pause</button>
    </div>
    <div id="waveform"></div>

    <script>
        let wavesurfer;

        function createWaveSurfer() {
            return WaveSurfer.create({
                container: '#waveform',
                height: 200,
                waveColor: '#FF3B30',
                progressColor: '#FF9500',
                cursorColor: '#fff',
                cursorWidth: 2,
                // barWidth: 1,
                barGap: 1,
                barRadius: 3,
                // 关键设置
                drawingMode: 'oscilloscope',  // 使用示波器模式
                normalize: true,
                splitChannels: false,
                // 波形对齐到中间
                verticalAlign: 'middle',
                // 渲染配置
                pixelRatio: 1,
                fillParent: true,
                interact: false,
                autoCenter: true,
                // 确保波形完整显示
                minPxPerSec: 1,
                maxCanvasWidth: 8000,
                // 自定义波形渲染
                backend: 'MediaElement'
            });
        }

        async function loadAudio() {
            if (wavesurfer) {
                wavesurfer.destroy();
            }
            
            wavesurfer = createWaveSurfer();

            try {
                await wavesurfer.load('./1-3.mp3');
                
                wavesurfer.on('ready', () => {
                    console.log('WaveSurfer is ready');
                });

                wavesurfer.on('error', (err) => {
                    console.error('WaveSurfer error:', err);
                });
            } catch (error) {
                console.error('Error loading audio:', error);
            }
        }

        function togglePlay() {
            if (!wavesurfer) return;
            
            if (wavesurfer.isPlaying()) {
                wavesurfer.pause();
            } else {
                wavesurfer.play();
            }
        }
    </script>
</body>
</html>